home *** CD-ROM | disk | FTP | other *** search
/ SCI Games E3 2005 Press Kit (USA) / SCI Games E3 2005 Press Kit (USA).bin / runme_mac.swf / scripts / __Packages / mx / controls / streamingmedia / PlayBar.as < prev    next >
Text File  |  2005-05-05  |  6KB  |  205 lines

  1. class mx.controls.streamingmedia.PlayBar extends MovieClip
  2. {
  3.    static var TEXT_ALPHA_DARK = 100;
  4.    static var TEXT_ALPHA_LIGHT = 50;
  5.    static var PULSE_DURATION = 1400;
  6.    static var ACTIVE_PULSE_PORTION = 0.4;
  7.    static var STREAMING_ID = "streaming";
  8.    static var PAUSED_ID = "paused";
  9.    function PlayBar()
  10.    {
  11.       super();
  12.       this.init();
  13.    }
  14.    function init()
  15.    {
  16.       this._controller = this._parent;
  17.       this.setCompletionPercentage(this._controller.__get__playPercent());
  18.       this.setTime(this._controller.__get__playTime());
  19.       this.draw();
  20.    }
  21.    function isVertical()
  22.    {
  23.       return !this._controller.__get__horizontal();
  24.    }
  25.    function getCompletionPercentage()
  26.    {
  27.       var _loc2_ = undefined;
  28.       if(this.isVertical())
  29.       {
  30.          _loc2_ = this.yToPercent(this._thumb._y);
  31.       }
  32.       else
  33.       {
  34.          _loc2_ = this.xToPercent(this._thumb._x);
  35.       }
  36.       return _loc2_;
  37.    }
  38.    function setCompletionPercentage(aPercentage)
  39.    {
  40.       aPercentage = Math.floor(aPercentage);
  41.       if(aPercentage < 1)
  42.       {
  43.          aPercentage = 1;
  44.       }
  45.       else if(aPercentage > 100)
  46.       {
  47.          aPercentage = 100;
  48.       }
  49.       if(this.isVertical())
  50.       {
  51.          var _loc3_ = this.percentToY(aPercentage);
  52.          this._thumb._y = this.getHeight() - _loc3_ - 9;
  53.       }
  54.       else
  55.       {
  56.          var _loc4_ = this.percentToX(aPercentage);
  57.          this._thumb._x = _loc4_;
  58.       }
  59.       this.updateHiliteToMatchThumb();
  60.    }
  61.    function updateHiliteToMatchThumb()
  62.    {
  63.       if(this.isVertical())
  64.       {
  65.          this._hilite._height = this.getHeight() - this._thumb._y - 6;
  66.          this._hilite._y = this.getHeight() - this._hilite._height - 1;
  67.       }
  68.       else
  69.       {
  70.          this._hilite._width = this._thumb._x + 4;
  71.       }
  72.    }
  73.    function setTime(aTime)
  74.    {
  75.       var _loc7_ = Math.floor(aTime / 3600);
  76.       var _loc3_ = aTime % 3600;
  77.       var _loc6_ = Math.floor(_loc3_ / 60);
  78.       _loc3_ %= 60;
  79.       var _loc5_ = Math.floor(_loc3_);
  80.       _loc3_ %= 1;
  81.       var _loc2_ = Math.round(_loc3_ * 1000);
  82.       var _loc4_ = _loc7_ + ":" + (_loc6_ >= 10 ? "" : "0") + _loc6_ + ":" + (_loc5_ >= 10 ? "" : "0") + _loc5_ + ".";
  83.       if(_loc2_ < 10)
  84.       {
  85.          _loc4_ += "00" + String(_loc2_);
  86.       }
  87.       else if(_loc2_ < 100)
  88.       {
  89.          _loc4_ += "0" + String(_loc2_);
  90.       }
  91.       else
  92.       {
  93.          _loc4_ += String(_loc2_);
  94.       }
  95.       this._timeTextField.text = _loc4_;
  96.    }
  97.    function setIsPlaying(isPlaying)
  98.    {
  99.       if(isPlaying)
  100.       {
  101.          this._statusTextField.text = this._controller.getLocalizedString(mx.controls.streamingmedia.PlayBar.STREAMING_ID);
  102.          delete this.onEnterFrame;
  103.          this.setDarkText();
  104.       }
  105.       else
  106.       {
  107.          this._statusTextField.text = this._controller.getLocalizedString(mx.controls.streamingmedia.PlayBar.PAUSED_ID);
  108.          this._darkenText = false;
  109.          this._textPulseTime = getTimer();
  110.          this.onEnterFrame = this.pulseText;
  111.       }
  112.    }
  113.    function getController()
  114.    {
  115.       return this._controller;
  116.    }
  117.    function draw()
  118.    {
  119.       var _loc2_ = this.getCompletionPercentage();
  120.       if(this.isVertical())
  121.       {
  122.          this._x = (this._controller.__get__width() - this.getWidth()) / 2;
  123.          this._y = 8;
  124.          this._tray.setHeight(this.getHeight());
  125.          this._statusTextField._y = this.getHeight() - 4;
  126.       }
  127.       else
  128.       {
  129.          this._x = 8;
  130.          this._tray.setWidth(this.getWidth());
  131.          this._timeTextField._x = this.getWidth() - this._timeTextField._width - 3;
  132.       }
  133.       this.setIsPlaying(this._controller.isPlaying());
  134.       this.setCompletionPercentage(_loc2_);
  135.    }
  136.    function getWidth()
  137.    {
  138.       var _loc2_ = !this.isVertical() ? this._controller.__get__width() - 16 : 20;
  139.       return _loc2_;
  140.    }
  141.    function getHeight()
  142.    {
  143.       var _loc2_ = !this.isVertical() ? 20 : this._controller.__get__height() - 90;
  144.       return _loc2_;
  145.    }
  146.    function xToPercent(x)
  147.    {
  148.       var _loc2_ = 100 * ((x + 3) / (this.getWidth() - 3));
  149.       return _loc2_;
  150.    }
  151.    function percentToX(percent)
  152.    {
  153.       var _loc2_ = (this.getWidth() - 3) * (percent / 100) - 3;
  154.       return _loc2_;
  155.    }
  156.    function yToPercent(y)
  157.    {
  158.       var _loc2_ = 100 * ((this.getHeight() - 3 - y) / this.getHeight());
  159.       return _loc2_;
  160.    }
  161.    function percentToY(percent)
  162.    {
  163.       var _loc2_ = (this.getHeight() - 3) * (percent / 100) - 3;
  164.       return _loc2_;
  165.    }
  166.    function pulseText()
  167.    {
  168.       var _loc2_ = getTimer() - this._textPulseTime;
  169.       var _loc5_ = Math.min(1,_loc2_ / mx.controls.streamingmedia.PlayBar.PULSE_DURATION);
  170.       var _loc7_ = mx.controls.streamingmedia.PlayBar.PULSE_DURATION * mx.controls.streamingmedia.PlayBar.ACTIVE_PULSE_PORTION;
  171.       var _loc6_ = Math.min(1,_loc2_ / _loc7_);
  172.       var _loc4_ = _loc6_ * (mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_DARK - mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_LIGHT);
  173.       var _loc3_ = !this._darkenText ? mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_DARK - _loc4_ : mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_LIGHT + _loc4_;
  174.       this._statusTextField._alpha = _loc3_;
  175.       this._timeTextField._alpha = _loc3_;
  176.       if(_loc5_ >= 1)
  177.       {
  178.          this._darkenText = !this._darkenText;
  179.          this._textPulseTime = getTimer();
  180.       }
  181.    }
  182.    function setDarkText()
  183.    {
  184.       this._statusTextField._alpha = mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_DARK;
  185.       this._timeTextField._alpha = mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_DARK;
  186.    }
  187.    function setLightText()
  188.    {
  189.       this._statusTextField._alpha = mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_LIGHT;
  190.       this._timeTextField._alpha = mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_LIGHT;
  191.    }
  192.    function get enabled()
  193.    {
  194.       return this._thumb.__get__enabled();
  195.    }
  196.    function set enabled(is)
  197.    {
  198.       this._thumb.__set__enabled(is);
  199.    }
  200.    function isScrubbing()
  201.    {
  202.       return this._thumb.isScrubbing();
  203.    }
  204. }
  205.